/**
 *<p>Copyright: CHINA NATIONAL SOFTWARE & SERVICE CO.,LTD.</p>
 */
package com.cssnb.commons.shiro;

import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.credential.SimpleCredentialsMatcher;

/**
 * @Company: 中国软件与技术服务股份有限公司宁波子公司
 * @Project: 鄞州国税-信息化资产管理系统
 * @Module ID:
 * @Description:
 * @JDK version used: JDK1.4
 * @Author: 卜繁晟
 * @Email: 5545795@qq.com | bufsh@css.com.cn
 * @Created Date: 2013-4-27 上午11:16:10
 */
public class MyCredentialsMatcher extends SimpleCredentialsMatcher {

	protected static final String ALGORITHM = "MD5";

	/**
	 * @Author: 卜繁晟
	 * @Created Date: 2013-4-27 上午11:16:32
	 */
	@Override
	public boolean doCredentialsMatch(AuthenticationToken token, AuthenticationInfo info){
//		Object tokenCredentials = encrypt(toBytes(token.getCredentials()));
//		Object accountCredentials = getCredentials(info);
//		return equals(tokenCredentials, accountCredentials);
		// return super.doCredentialsMatch(token, info);
		char[] pass_input = (char[]) token.getCredentials();
		char[] pass_db = (char[]) info.getCredentials();
		String password = "", password_db = "";
		for(char p : pass_input){
			password += p;
		}
		for(char p : pass_db){
			password_db += p;
		}
		boolean auth = false;
		if(!password_db.isEmpty()){
			String dbsalt = password_db.substring(0, 16);
			password_db = password_db.substring(16);
			try{
				auth = PasswordCheckUtil.checkPassword(password, password_db, dbsalt);
			}catch(Exception e){
				e.printStackTrace();
			}
		}
		return auth;
	}
}